package com.xioz.android;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Preferences;
import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.BitmapFont;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Vector3;

/**
 * ScoreMenu Class
 * For a particular game, displays high scores
 * 
 * @author Zong Xiong
 */
public class ScoreMenu implements MenuType{
	
/***************************************************
 * Fields
 ***************************************************/
	
	MenuType previousMenu;
	int selection = 0;
	private String scoreOf;
	private Preferences prefs;
	
/***************************************************
 * Public Methods
 ***************************************************/
	
	/**
	 * Default Constructor
	 * creates menu with parent menu
	 * 
	 * @param oldMenu, parent menu
	 */
	public ScoreMenu(MenuType oldMenu, String scoreType) {
		previousMenu = oldMenu;
		scoreOf = scoreType;
		prefs = Gdx.app.getPreferences(scoreOf + "WordGame");
	}

	/** {@inheritDoc} */
	@Override
	public void draw(SpriteBatch batch, TextureRegion inactiveButton,
			TextureRegion activeButton, TextureRegion textBar, TextureRegion grayBar, 
			BitmapFont menuFont, BitmapFont textFont) {
		// print grayBar and enlargen to screen
		batch.draw(grayBar, 30, 20, 260, 440);
		
		// set fonts to white and print header
		menuFont.setColor(Color.WHITE);
		textFont.setColor(Color.WHITE);
		textFont.draw(batch, "Scoreboard for " + scoreOf, 45, 430);
		
		// we check if we are printing a destroyer scoreboard, if so we need to print the times properly
		if (scoreOf.equals("Destroyer")) {
			GameTimer temp = new GameTimer();
			for (int i = 1; i < 6; i++) {
				temp.setTime(prefs.getLong("Place"+i+"Score"));
				menuFont.draw(batch, i + "." + prefs.getString("Place" +i+"Name") + " - " + 
								temp.printTime(), 40, 410 - i * 60);
			}
		}
		// if not we simply print the name and score
		else {
			for (int i = 1; i < 6; i++) {
				menuFont.draw(batch, i + "." + prefs.getString("Place" +i+"Name") + " - " + 
								prefs.getLong("Place"+i+"Score"), 40, 410 - i * 60);
			}
		}
	}

	/** {@inheritDoc} */
	@Override
	public MenuType getPreviousMenu() {
		// TODO Auto-generated method stub
		return previousMenu;
	}

	/** {@inheritDoc} */
	@Override
	public MenuType getMenuOption(Vector3 pointer) {
		// we return the parent menu regardless since this has no sub menus
		return previousMenu;
	}

	/** {@inheritDoc} */
	@Override
	public void setVisible(boolean visibility) {
		// TODO Auto-generated method stub
		
	}

	/** {@inheritDoc} */
	@Override
	public boolean isVisible() {
		// TODO Auto-generated method stub
		return false;
	}

}

